package com.ctrip.demo.leetcode;

public class LeetCode1108 {

    public static void main(String[] args) {
        System.out.println(defangIPaddr("1.1.1.1"));
        System.out.println(defangIPaddr1("1.1.1.1"));
    }

    public static String defangIPaddr(String address) {

        try {
            int i = 1 / 0;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return address.replace(".", "[.]");

    }

    public static String defangIPaddr1(String address) {
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < address.length(); i++) {
            if (address.charAt(i) == '.') {
                stringBuilder.append("[.]");
            } else {
                stringBuilder.append(address.charAt(i));
            }
        }
        return stringBuilder.toString();
    }


}
